﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.Admin.Page_Template
{
    public partial class TemplateCodeEditor : Evan.WebUI.ManagerPage
    {
        protected int Id = 0;
        protected dynamic Model = new Evan.Model.DynamicModel();
        protected string FileContent = "";
        protected string TemplateCategory = "";
        protected string FilePath = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //仅仅只有超级管理员拥有此功能
                if (!Evan.Member.Administrator.IsSuperAdmin())
                {
                    VerifyRoles();
                }

                int.TryParse(Evan.Common.CommFun.GetQueryString("Id"), out Id);
                if (Id==0)
                {
                    throw new Exception("参数 Id 不能为空");
                }

                Model = new Evan.DataBase.DbOperat("Template").GetModel(Id);
                if (Model.TemplateCategory=="Component")
                {
                    TemplateCategory = "组件";
                    FilePath = "/templates/_include/" + (string.IsNullOrEmpty(Model.TemplatePath) ? "" : Model.TemplatePath + "/") + Model.TemplateName + ".html";
                    FileContent = Evan.Common.DirFile.ReadFile(FilePath);
                }
                if (Model.TemplateCategory == "Template")
                {
                    TemplateCategory = "模板";
                    FilePath = "/templates/" + (string.IsNullOrEmpty(Model.TemplatePath) ? "" : Model.TemplatePath + "/") + Model.TemplateName + ".aspx";
                    FileContent = Evan.Common.DirFile.ReadFile(FilePath);
                }
                
            }
        }
    }
}